/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CompanyInfo;
/*     */ import com.newcrm.bean.Group;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.TaskManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.List;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class ListTasks extends AbstractAction
/*     */ {
/*  35 */   private static Logger logger = Logger.getLogger(ListTasks.class.getName());
/*     */ 
/*     */   public ListTasks(AbstractHttpServlet servlet) {
/*  38 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  45 */     User user = super.getLoginUser(request);
/*  46 */     String userId = user.userId;
/*     */ 
/*  48 */     TaskManager manager = new TaskManager();
/*     */ 
/*  50 */     int category = 
/*  51 */       Util.getURLIntParameter(request.getParameter("category"));
/*     */ 
/*  53 */     int referenceId = Util.getURLIntParameter(request
/*  54 */       .getParameter("referenceId"));
/*  55 */     int referenceType = Util.getURLIntParameter(request
/*  56 */       .getParameter("referenceType"));
/*     */ 
/*  58 */     int offset = Util.getURLIntParameter(request.getParameter("offset"));
/*     */ 
/*  61 */     int status = Util.getURLIntParameter(request.getParameter("status"));
/*     */ 
/*  63 */     String responsibleUserId = Util.getURLParameter(request
/*  64 */       .getParameter("responsibleUserId"));
/*     */ 
/*  66 */     String groupIds = "";
/*  67 */     if ((responsibleUserId == null) || (responsibleUserId.trim().length() == 0))
/*     */     {
/*  69 */       if (!user.isAdmin)
/*     */       {
/*  71 */         if (user.isGroupAdmin)
/*     */         {
/*  73 */           CompanyInfo companyInfo = super.getCompany(request);
/*  74 */           Group group = companyInfo.getGroupById(user.groupId);
/*  75 */           if (group != null)
/*  76 */             groupIds = group.getAllIds();
/*     */           else
/*  78 */             groupIds = String.valueOf(user.groupId);
/*     */         }
/*     */         else
/*     */         {
/*  82 */           responsibleUserId = userId;
/*     */         }
/*     */       }
/*     */     }
/*  86 */     else if ((!user.isAdmin) && (!user.isGroupAdmin))
/*     */     {
/*  88 */       responsibleUserId = userId;
/*  89 */     } else if ((!user.isAdmin) && (user.isGroupAdmin))
/*     */     {
/*  91 */       CompanyInfo companyInfo = super.getCompany(request);
/*  92 */       User responsibleUser = companyInfo.getUser(responsibleUserId);
/*  93 */       if (!companyInfo.isGroupAdmin(user, responsibleUser.groupId))
/*     */       {
/*  95 */         responsibleUserId = userId;
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 100 */     response.setContentType("text/html;charset=utf-8");
/* 101 */     PrintWriter out = response.getWriter();
/* 102 */     JSONObject jsonObject = new JSONObject();
/*     */     try {
/* 104 */       List result = manager.getList(referenceId, 
/* 105 */         referenceType, status, category, responsibleUserId, 
/* 106 */         groupIds, user.companyId, offset, 10);
/* 107 */       jsonObject.put("error", "0");
/* 108 */       jsonObject.put("tasks", result);
/*     */     } catch (Exception e) {
/* 110 */       logger.warn("get task failed", e);
/* 111 */       jsonObject.put("error", "1");
/* 112 */       jsonObject.put("msg", "加载任务出错，请稍后再试");
/*     */     }
/* 114 */     out.println(jsonObject);
/* 115 */     out.flush();
/* 116 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ListTasks
 * JD-Core Version:    0.6.1
 */